package cn.lliiooll.listener;

import cn.lliiooll.Mentor;
import cn.lliiooll.evt.PlayerDelMentorEvent;
import cn.lliiooll.evt.PlayerDelPupilEvent;
import cn.lliiooll.evt.PlayerMakeMentorEvent;
import cn.lliiooll.evt.PlayerMakePupilEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

public class MainListener implements Listener {

    @EventHandler
    public void onMakeShiFu(PlayerMakeMentorEvent e){
        String msg = Mentor.m.getConfig().getString("broadcast.makementor.msg").replaceAll("@player@",e.getPlayer().getName());
        if(Mentor.m.getConfig().get("broadcast.makementor.permission") == null){
           Mentor.m.broadcastMessage(msg.replaceAll("@mentor@",e.getShifu().getPlayer().getName()));
        }else{
            Mentor.m.broadcast(msg.replaceAll("@mentor@",e.getShifu().getPlayer().getName()),Mentor.m.getConfig().getString("broadcast.makementor.permission"));
        }

    }
    @EventHandler
    public void onDelShiFu(PlayerDelMentorEvent e){
        String msg = Mentor.m.getConfig().getString("broadcast.delmentor.msg").replaceAll("@player@",e.getPlayer().getName());
        if(Mentor.m.getConfig().get("broadcast.delmentor.permission") == null){
            Mentor.m.broadcastMessage(msg.replaceAll("@mentor@",e.getShifu().getPlayer().getName()));
        }else{
            Mentor.m.broadcast(msg.replaceAll("@mentor@",e.getShifu().getPlayer().getName()),Mentor.m.getConfig().getString("broadcast.delmentor.permission"));
        }

    }

    @EventHandler
    public void onMakeTuDi(PlayerMakePupilEvent e){
        String msg = Mentor.m.getConfig().getString("broadcast.makepupil.msg").replaceAll("@player@",e.getPlayer().getName());
        if(Mentor.m.getConfig().get("broadcast.makepupil.permission") == null){
            new Mentor().broadcastMessage(msg.replaceAll("@pupil@",e.getTuDi().getPlayer().getName()));
        }else{
            new Mentor().broadcast(msg.replaceAll("@pupil@",e.getTuDi().getPlayer().getName()),Mentor.m.getConfig().getString("broadcast.makepupil.permission"));
        }
    }
    @EventHandler
    public void onDelTuDi(PlayerDelPupilEvent e){
        String msg = Mentor.m.getConfig().getString("broadcast.delpupil.msg").replaceAll("@player@",e.getPlayer().getName());
        if(Mentor.m.getConfig().get("broadcast.delpupil.permission") == null){
            new Mentor().broadcastMessage(msg.replaceAll("@pupil@",e.getTuDi().getPlayer().getName()));
        }else{
            new Mentor().broadcast(msg.replaceAll("@pupil@",e.getTuDi().getPlayer().getName()),Mentor.m.getConfig().getString("broadcast.delpupil.permission"));
        }
    }
}
